package cn.bone.ou.data.controller;

import cn.bone.base.bean.CommonResult;
import cn.bone.base.bean.Ref;
import cn.bone.base.utils.StringUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/ou/upload")
public class UploadController {

    @RequestMapping("/file")
    public CommonResult file(Integer communityId,
                             @RequestParam("file")MultipartFile multipartFile){
        if(multipartFile==null){
            return Ref.error("没有文件上传");
        }
        if(multipartFile.isEmpty()){
            return Ref.error("文件上传错误");
        }

        if(communityId==null){
            return Ref.error("小区编号不能为空");
        }

        Map<String,String> map = new HashMap<>();
        map.put("url","http://47.96.109.220/images/1.jpg");
        return Ref.ok(map);
    }

    @RequestMapping("/base64")
    public CommonResult base64(Integer communityId,String base64Str){
        if(communityId==null){
            return Ref.error("小区编号不能为空");
        }
        if(StringUtil.isEmpty(base64Str)){
            return Ref.error("base64字符串不能为空");
        }
        Map<String,String> map = new HashMap<>();
        map.put("url","http://47.96.109.220/images/1.jpg");
        return Ref.ok(map);
    }
}
